//
//  NSArray+ZZZCategory.m
//  zjhealth
//
//  Created by 张润东 on 2017/11/30.
//  Copyright © 2017年 amu. All rights reserved.
//

#import "NSArray+ZZZCategory.h"
#import "NSDate+common.h"
#import "NSString+Common.h"

@implementation NSArray (ZZZCategory)

+ (NSArray *)getArray:(NSArray *)array{
    if ([array isKindOfClass:[NSArray class]]) {
        return array;
    }else{
        NSArray *temp = [[NSArray alloc]init];
        return temp;
    }
    
}

+ (NSMutableArray *)getMutArray:(NSArray *)array {
    if ([array isKindOfClass:[NSArray class]]) {
        return [[NSMutableArray alloc] initWithArray:array];
    }else{
        NSMutableArray *temp = [[NSMutableArray alloc]init];
        return temp;
    }
}

+ (NSArray*)getDatesWithStartDate:(NSString *)startDate endDate:(NSString *)endDate {
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSCalendarIdentifierGregorian];
    
    //字符串转时间
    NSDateFormatter *matter = [[NSDateFormatter alloc] init];
    matter.dateFormat = @"yyyy-MM-dd";
    NSDate *start = [matter dateFromString:startDate];
    NSDate *end = [matter dateFromString:endDate];
    
    NSMutableArray *componentAarray = [NSMutableArray array];
    NSComparisonResult result = [start compare:end];
    NSDateComponents *comps;
    while (result != NSOrderedDescending) {
        comps = [calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay |  NSCalendarUnitWeekday fromDate:start];
        //        [componentAarray addObject:start];
        [componentAarray addObject:[start formattedTimeWithFormat:@"yyyy-MM-dd"]];
        //后一天
        [comps setDay:([comps day]+1)];
        start = [calendar dateFromComponents:comps];
        //对比日期大小
        result = [start compare:end];
    }
    return componentAarray;
}


//性别编码转中文
+ (NSString *)gl_sexNameByCode:(id)sexCode {
    if ([sexCode isKindOfClass:[NSString class]]) {
        if ([NSString isBlankString:sexCode]||[@"0"isEqualToString:sexCode]) {
            return @"";
        }else if ([@"1" isEqualToString:sexCode]) {
            return @"男";
        }else {
            return @"女";
        }
    }else if ([sexCode isKindOfClass:[NSNumber class]]) {
        NSInteger code = [sexCode intValue];
        if (code == 0) {
            return @"";
        }else if(code == 1) {
            return @"男";
        }else {
            return @"女";
        }
    }
    return @"";
}

@end
